#pragma once

#include <iostream>
#include <string>

class Component
{
public:
    Component()          = default;
    virtual ~Component() = default;

public:
    virtual void add(Component *component)    = 0;
    virtual void remove(Component *component) = 0;
    virtual void operation()                  = 0;

    void setParent(Component *component)
    {
        m_parent = component;
    }

    Component *getParent()
    {
        return m_parent;
    }

private:
    Component *m_parent;
};

class Leaf : public Component
{
public:
    Leaf(std::string name)
    {
        this->m_name = name;
    }

public:
    void add(Component *component)
    {
    }

    void remove(Component *component)
    {
    }

    void operation()
    {
        std::cout << "叶子 " + m_name << " 被访问" << std::endl;
    }

private:
    std::string m_name;
};